from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponse
import redis

#add/delete infomation of jiaoxuedian
def jxd(request):
    r = redis.Redis(host='127.0.0.1', db=1)
    errors = []
    if 'op' in request.POST:
        if request.POST['op'] == 'add':
            shi = request.POST.get('shi')
            jxd = request.POST.get('jxd')
            r.sadd('jxd_'+shi, jxd)
        elif request.POST['op'] == 'del':
            name = request.POST.get('jxd_del').split('.')
            shi = name[0]
            jxd = name[1]
            r.srem('jxd_'+shi, jxd)
        else:
            errors.apped("give a operate?")
    
    #get all jiaoxuedian
    jxd_list = []
    for shi in r.keys('jxd_*'):
        for jxd in r.smembers(shi):
            jxd_list.append((shi[4:], jxd))
    return render_to_response('tdm_admin_template.html', locals(), context_instance=RequestContext(request))

